package com.example._07servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

public class RequestApi2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String[] temp = req.getParameterValues("temp");
        System.out.println(" 姓名:"+username + " 密码:："+password+" 选项:"+ Arrays.toString(temp));

        PrintWriter writer = resp.getWriter();
        writer.println("回传数据测试："+" 姓名:"+username + " 密码:："+password+" 选项:"+ Arrays.toString(temp));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String[] temp = req.getParameterValues("temp");
        System.out.println(" 姓名:"+username + " 密码:："+password+" 选项:"+ Arrays.toString(temp));

    }
}
